using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.RecipeFramework.Extensions.CommonHelpers;

namespace Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel.NamingConventions
{
    /// <summary>
    /// Implements the <see cref="NamingStrategy"/> appropriately based on
    /// naming conventions for SQL Server.
    /// </summary>
    public sealed class SqlServerNamingStrategy : NamingStrategy
    {
        #region NamingStrategy Members

        public override string GetFieldName(string type)
        {
            string response = type;

            if (!String.IsNullOrEmpty(response))
            {
                response = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}Field", response);
                response = GetVariableName(response);
            }

            return response;
        }

        public override string GetMethodParameterName(string type)
        {
            string response = type;

            if (!String.IsNullOrEmpty(response))
            {
                response = string.Format(System.Globalization.CultureInfo.CurrentCulture, "{0}", response);
                response = base.GetVariableName(response);
            }

            return response;
        }

        public override string GetPropertyName(string type)
        {
            string response = type;

            if (!String.IsNullOrEmpty(response))
            {
                response = response.Substring(0, 1).ToUpper() + response.Substring(1);
            }

            return response;
        }

        public override string GetVariableName(string type, bool convertToValidIdentifier)
        {
            string response = type;

            if (!String.IsNullOrEmpty(response))
            {
                response = response.Substring(0, 1).ToLower() + response.Substring(1);

                if (convertToValidIdentifier)
                {
                    response = CodeDomHelper.ConvertToValidIdentifier(response);
                }
            }

            return response;
        }

        #endregion
    }
}
